package com.jz.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by Administrator on 2015/10/23.
 */
public class TimeUtil {

    private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * date时间早于当前时间second秒
     * */
    public static boolean beforeNow(String date,int second){
        return ((new Date().getTime() - convertStr2Date(date).getTime())/1000 - second) >= 0;
    }

    public static String getTime(){
        return sf.format(new Date());
    }

    public static String getUtcTime(){
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sf.setTimeZone(TimeZone.getTimeZone("GMT-0"));
        return sf.format(new Date());
    }

    public static Date convertStr2Date(String str){
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String getDistantYear(){
        return "1900-01-01 00:00:00";
    }

    public static void main(String[] r){
        String a = "2015-01-01 00:00:00";
        String b = "2015-01-01 00:00:10";
        Date da = convertStr2Date(a);
        Date db = convertStr2Date(b);
        long te = db.getTime() - da.getTime();

//        System.out.println(db.after(da));
//        System.out.println(te/1000);
//        System.out.println(isAfter("2015-01-01 00:00:20","2015-01-01 00:00:10",103));
        String date = "2015-11-16 15:10:10";
//        long n =new Date().getTime();
//        long d = convertStr2Date(date).getTime();
//        System.out.println(n);
//        System.out.println(d);
//        System.out.println((n - d) / 1000);
        System.out.println(beforeNow(date, 20));
    }
}
